﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public delegate void InvokeFunc();

public class AppInit : MonoBehaviour {

    Dictionary<Step, InvokeFunc> updateDict = new Dictionary<Step, InvokeFunc>();
    private static AppInit mInstance = null;
    public static AppInit Instance { get { return mInstance;  } }
    void Awake()
    {
        mInstance = this;
        //NoticeCtrl.Instance
    }
	void Start () 
    {
        AppManager.Instance.Enter();
	}


    public void AddUpdateFunc(Step key,InvokeFunc updateFunc)
    {
        if (updateDict.ContainsKey(key))
        {
            return;
        }

        updateDict.Add(key, updateFunc);
    }

    public void RemoveUpdateFunc(Step key)
    {
        if (updateDict.ContainsKey(key))
        {
            updateDict.Remove(key);
        }
    }

    void Update()
    {
        if (updateDict.Count == 0) return;
        var funcs = updateDict.Values;

        var tFuncList = new List<InvokeFunc>();
        foreach (var func in funcs) tFuncList.Add(func);

        var funcsArr = tFuncList.ToArray();
        for (int i = 0; i < funcsArr.Length; ++i) funcsArr[i]();
    }

    void OnGUI()
    {
        if (GUILayout.Button("Test"))
        {
            Timer.Instance.Stop();
            Timer.Instance.SetCallBack((int passSecond) =>
            {
                Debug.Log("passSecond:  "  + passSecond);
            }, 1f);

            Timer.Instance.Run();
        }
    }
}
